package com.yimi.yinhepda.utils;

import android.content.Context;
import android.content.Intent;

import com.pda.ym.utils.Constants;

/**
 * 项目名称：yimi2
 * 创建时间：2016/12/5 15:20
 * 版本号：1.0
 * 功能描述 扫描控制工具
 *
 * @author 刘宏恩
 */
public class ScanToolControlUtil {
  private ScanToolControlUtil() {
  }

  private static class ScanToolControlHolder {
    private static ScanToolControlUtil scanToolControlInstance;

    static {
      scanToolControlInstance = new ScanToolControlUtil();
    }
  }

  public static ScanToolControlUtil getInstance() {
    return ScanToolControlHolder.scanToolControlInstance;
  }

  /**
   * 修改广播名称和键值
   */
  public void setBroadCastName(Context context) {
    Intent barCodeIntent = new Intent(Constants.ACTION_SCANNER_APP_SETTINGS);
    barCodeIntent.putExtra(Constants.TYPE_BARCODE_BROADCAST_ACTION, Constants.BARCODE_ACTION);
    barCodeIntent.putExtra(Constants.TYPE_BARCODE_BROADCAST_KEY, Constants.BARCODE_VALUE);
    context.sendBroadcast(barCodeIntent);
  }

  /**
   * 修改广播结束符
   */
  public void setBroadCastEndChar(Context context) {
    Intent barCodeIntent = new Intent(Constants.ACTION_SCANNER_APP_SETTINGS);
    barCodeIntent.putExtra(Constants.TYPE_END_CHAR, EndChar.NONE + "");
    context.sendBroadcast(barCodeIntent);
  }

  /**
   * 设置扫描声音
   */
  public void setScanSound(Context context) {
    Intent barCodeIntent = new Intent(Constants.ACTION_SCANNER_APP_SETTINGS);
    barCodeIntent.putExtra(Constants.TYPE_PLAYSOUND, false);
    context.sendBroadcast(barCodeIntent);
  }

  /**
   * 设置开机自启动
   */
  public void setBootStart(Context context) {
    Intent barCodeIntent = new Intent(Constants.ACTION_SCANNER_APP_SETTINGS);
    barCodeIntent.putExtra(Constants.TYPE_BOOT_START, true);
    context.sendBroadcast(barCodeIntent);
  }

  /**
   * 条码结束符枚举类
   */
  public enum EndChar {
    ENTER, TAB, SPACE, NONE;
  }
}
